<template>
	<view class="home">
		<!--  轮播图  -->
		<swiper indicator-dots="true" indicator-color="#fff" indicator-active-color="red" circular="true"
			autoplay="true" interval="2000">
			<swiper-item v-for="(item,index) in swipers" :key="index">
				<image :src="item.image" alt="">
			</swiper-item>
		</swiper>
		<!--  导航区  -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.tit}}</text>
			</view>
		</view>
		<!--  推荐商品  -->
		<view class="hot_goods">
			<view class="tit">
				推荐商品
			</view>
			<goodsList :goods="goods"></goodsList>
			<view class="isOver" v-if="flag" style="text-align: center;font-size: 30rpx;">------我是有底线的------</view>
		</view>
	</view>
</template>

<script>
	import goodsList from "../../components/goos-list/goods-list.vue"
	export default {
		data() {
			return {
				swipers: [],
				goods: [],
				navs: [{
						icon: "iconfont icon-ziyuan",
						tit: "黑马超市",
						path: "../goods/goods"
					},
					{
						icon: "iconfont icon-guanyuwomen",
						tit: "联系我们",
						path: "../contact/contact"
					},
					{
						icon: "iconfont icon-tupian",
						tit: "社区图片",
						path: "../pics/pics"
					},
					{
						icon: "iconfont icon-shipin",
						tit: "学习视频",
						path: "../videos/videos"
					},
				],
				totalAll: 1000,
				flag: false,
				page:1
			}
		},
		onLoad() {
			this.getSwipers()
			this.getHotGoods()
		},
		onReachBottom() {
			if (this.goods.length >= this.totalAll) {
				this.flag = true
			}
			this.page++
			this.getHotGoods()
		},
		components: {
			goodsList
		},
		methods: {
			async getSwipers() {
				const res = await this.$myRequest({
					url: "/home/multidata"
				})
				if (res) {
					this.swipers = res.data.data.banner.list
				}
			},
			async getHotGoods() {
				const res = await this.$myRequest({
					url: "/home/data",
					data: {
						type: "new",
						page: this.page
					}
				})
				if (res) {
					this.totalAll = res.data.data.total
					this.goods = [...this.goods, ...res.data.data.list]
				}
			},
			navItemClick(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	.home {
		swiper {
			width: 750rpx;
			height: 380rpx;

			image {
				height: 100%;
				width: 100%;
			}
		}
	}

	.nav {
		display: flex;

		.nav_item {
			width: 25%;
			text-align: center;

			view {
				width: 120rpx;
				height: 120rpx;
				background: $shop;
				border-radius: 60rpx;
				margin: 10px auto;
				line-height: 120rpx;
				color: #fff;
				font-size: 50rpx;
			}

			.icon-tupian {
				font-size: 45rpx;
			}

			text {
				font-size: 30rpx;
			}
		}
	}

	.hot_goods {
		background: #eee;
		overflow: hidden;
		margin-top: 15rpx;

		.tit {
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			color: $shop;
			letter-spacing: 40rpx;
			background: #fff;
			margin: 12rpx 0;
		}
	}
</style>
